/**
 * @file osplatform.h
 * @author 王雷
 * @brief 系统API定义
 * @version 0.1
 * @date 2022-11-3
 * @copyright Copyright 2022 Langge Software Co., Ltd. All rights reserved.
 */

#ifndef __OS_OSPLATFORM_API_H__
#define __OS_OSPLATFORM_API_H__

#include "ossymbols.h"
#include <stdint.h>
// #ifdef ANDROID

// #elif WIN32_PC 

// #elif IOS

// #elif MAC

// #elif UNIX_LIKE

// #endif

#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
#define OSAPIENTRY __stdcall
#endif

#ifndef OSAPIENTRY
#define OSAPIENTRY
#endif
#ifndef OSAPIENTRYP
#define OSAPIENTRYP OSAPIENTRY *
#endif


typedef uint64_t osThreadID;
typedef uint64_t osPID;
typedef int32_t osThreadTLS;


OS_API int32_t osPlatformLoader(const char * ver);
OS_API void osPlatformUnLoader();


/******************************************************************
 * @brief  系统函数-系统运行环境信息获取与运行状态捕获
 * @author Lei.Wang93@geely.com
*******************************************************************/




struct SystemInfo_OS{
    
};



struct MinidumpContext_OS {
    void * CpuSlice;
};


struct MinidumpDescriptor_OS{
    int32_t type;
    osPID       CurPID;
    osThreadID  CurTID;
    osPID       DumpPID;
    osThreadID  DumpTID;

};

// enum class CPUCategory_OS{
    
    
// };


typedef int64_t (*DumpMessageProc_OS)(MinidumpDescriptor_OS * minidump,void * context);
struct RegisterException_OS{
    DumpMessageProc_OS proc;
};



typedef  int32_t (OSAPIENTRYP PLATFORM_GETSYSTEMINFO_PROC)(struct SystemInfo_OS &);
OSPL_API PLATFORM_GETSYSTEMINFO_PROC osGetSystemInfo;

typedef  int32_t (OSAPIENTRYP PLATFORM_SETEXCEPTIONFILTER_PROC)(RegisterException_OS & exception);
OSPL_API PLATFORM_SETEXCEPTIONFILTER_PROC osSetExceptionFilter;


/******************************************************************
 * @brief  系统函数-线程控制
 * @author Lei.Wang93@geely.com
*******************************************************************/

typedef uint64_t (* __thread_entry_func)(void*);

struct Paramer_osThreadCreate{
    int32_t stacksize; 
};

struct osThreadObjectDescribe{
    osThreadID id;
    
};

typedef  int32_t (OSAPIENTRYP PLATFORM_THREADCREATE_PROC)(osThreadID * id,const Paramer_osThreadCreate & paramer,__thread_entry_func startfunc,void* arg);
OSPL_API PLATFORM_THREADCREATE_PROC osCreateThread;

typedef  void (OSAPIENTRYP PLATFORM_THREADEXIT_PROC)(uint64_t exitcode);
OSPL_API PLATFORM_THREADEXIT_PROC osExitThread;

typedef  int32_t (OSAPIENTRYP PLATFORM_THREADATTACH_PROC)();
OSPL_API PLATFORM_THREADATTACH_PROC osAttachThread;

typedef  void (OSAPIENTRYP PLATFORM_THREADDEATTACH_PROC)();
OSPL_API PLATFORM_THREADDEATTACH_PROC osDeAttachThread;

typedef  osThreadID (OSAPIENTRYP PLATFORM_GETTHREADID_PROC)();
OSPL_API PLATFORM_GETTHREADID_PROC osGetThreadID;

typedef  osPID (OSAPIENTRYP PLATFORM_GETPID_PROC)();
OSPL_API PLATFORM_GETPID_PROC osGetPID;


typedef  int32_t (OSAPIENTRYP PLATFORM_THREADLOCALSTORE_ALLOC_PROC)(osThreadTLS * tls);
OSPL_API PLATFORM_THREADLOCALSTORE_ALLOC_PROC osAllocThreadLocalSotre;

typedef int32_t (OSAPIENTRYP PLATFORM_THREADLOCALSTORE_FREE_PROC)(osThreadTLS * tls);
OSPL_API PLATFORM_THREADLOCALSTORE_FREE_PROC osFreeThreadLocalSotre;

typedef  void (OSAPIENTRYP PLATFORM_THREADLOCALSTORE_SET_PROC)(const osThreadTLS * tls,void * value);
OSPL_API PLATFORM_THREADLOCALSTORE_SET_PROC osSetThreadLocalSotre;

typedef  void * (OSAPIENTRYP PLATFORM_THREADLOCALSTORE_GET_PROC)(const osThreadTLS * tls);
OSPL_API PLATFORM_THREADLOCALSTORE_GET_PROC osGetThreadLocalSotre;




#endif



